const mysql = require('mysql2')

// 创建连接池
const pool = mysql.createPool({
  host: 'localhost',
  user: 'root',
  password: 'password',
  database: 'm_toutiao_api',
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
})

exports.query = function (sql) {
  return new Promise((resolve, reject) => {
    pool.execute(sql, function (err, results, fields) {
      if (err) {
        return reject(err)
      }
      resolve(results)
    })
  })
}
